//
//  MTAllopatryWarningView.swift
//  MT
//
//  Created by ooops on 2020/5/29.
//  Copyright © 2020 张强. All rights reserved.
//

import UIKit
import MTCategory

class MTAllopatryWarningView: UIView {
    
    convenience init(title: String, content: String) {
        self.init()
        titleLabel.text = title
        subTitleLabel.text = content
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        makeConstraint()
        backgroundColor = UIColor(hex: 0x000000, alpha: 0.5)
    }
    
    lazy var centerView: UIView = {
        let v = UIView()
        v.backgroundColor = .white
        v.layer.cornerRadius = 8
        return v
    }()
    
    lazy var titleLabel: UILabel = {
        let l = UILabel()
        l.font = PingFangSCSemiboldFont(16)
        l.textColor = UIColor.text.x1d1a1a
        l.text = "为异地成员提供酒店机票提醒"
        return l
    }()
    
    lazy var subTitleLabel: UILabel = {
        let l = UILabel()
        l.font = PingFangSCRegularFont(14)
        l.textColor = UIColor.text.x1d1a1a
        l.numberOfLines = 0
        l.text = "确认后即需要为异地成员提供酒店或机票等相关任务支持。期间产生的经济支付方式（发布者直接支付或报名者垫付），以及毁约后产生的经济损失建议双方提前协商。平台将不予参与。"
        return l
    }()
    
    lazy var cancelButton: UIButton = {
        let btn = UIButton(type: .custom)
        btn.setTitle("我知道了", for: .normal)
        btn.backgroundColor = UIColor(hex: 0xffc000)
        btn.addTarget(self, action: #selector(MTAllopatryWarningView.cancel), for: .touchUpInside)
        btn.setTitleColor(UIColor.text.x1d1a1a, for: .normal)
        btn.titleLabel?.font = PingFangSCSemiboldFont(16)
        btn.layer.cornerRadius = 19.5
        btn.layer.masksToBounds = true
        return btn
    }()
    
    @objc private func cancel() {
        self.removeFromSuperview()
        
    }
    
    private func setupUI() {
        addSubview(centerView)
        centerView.addSubview(titleLabel)
        centerView.addSubview(subTitleLabel)
        centerView.addSubview(cancelButton)
    }
    
    private func makeConstraint() {
        centerView.snp.makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 325, height: 273))
            make.center.equalToSuperview()
        }
        
        titleLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(32)
        }
        
        subTitleLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(titleLabel.snp.bottom).offset(24)
            make.left.equalToSuperview().offset(24)
            make.right.equalToSuperview().offset(-24)
        }
        
        cancelButton.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.bottom.equalToSuperview().offset(-27)
            make.size.equalTo(CGSize(width: 208, height: 39))
        }
        
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }


}
